package Midium;
// 12.整数转罗马数字
public class Solution12 {
    public String intToRoman(int num) {
        StringBuffer roman = new StringBuffer();
        for(;num-1000>=0;num-=1000){
            roman.append('M');
        }
        if(num-900>=0){
            roman.append("CM");
            num-=900;
        }
        if(num-500>=0){
            roman.append('D');
            num-=500;
        }
        if(num-400>=0){
            roman.append("CD");
            num-=400;
        }
        for(;num-100>=0;num-=100){
            roman.append('C');
        }
        if(num-90>=0){
            roman.append("XC");
            num-=90;
        }
        if(num-50>=0){
            roman.append('L');
            num-=50;
        }
        if(num-40>=0){
            roman.append("XL");
            num-=40;
        }
        for(;num-10>=0;num-=10){
            roman.append('X');
        }
        if(num-9>=0){
            roman.append("IX");
            num-=9;
        }
        if(num-5>=0){
            roman.append('V');
            num-=5;
        }
        if(num-4>=0){
            roman.append("IV");
            num-=4;
        }
        for(;num-1>=0;num-=1){
            roman.append('I');
        }
        return roman.toString();
    }

    public static void main(String[] args) {
        Solution12 s12 = new Solution12();
        System.out.println(s12.intToRoman(3349));
    }
}
